package com.heima.minio;

import io.minio.MinioClient;
import io.minio.PutObjectArgs;
import io.minio.errors.*;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

public class MinIoTest {
    public static void main(String[] args) throws IOException, ServerException, InvalidBucketNameException, InsufficientDataException, ErrorResponseException, NoSuchAlgorithmException, InvalidKeyException, InvalidResponseException, XmlParserException, InternalException {
        FileInputStream is = new FileInputStream(new File("E:\\photo\\2037661.jpg"));
        //1.创建minio链接客户端
        MinioClient minioClient = MinioClient.builder().credentials("minio", "minio123")
                .endpoint("http://192.168.200.130:9000").build();
        PutObjectArgs putObjectArgs = PutObjectArgs.builder()
//                指定文件名
                .object("2037661.jpg")
//                指定文件类型
                .contentType("image/jpg")
//                指定桶名称
                .bucket("leadnews")
//                文件输入流   文件大小        分块传输  -1为不分块
                .stream(is,is.available(),-1)
                .build();
        //上传文件
        minioClient.putObject(putObjectArgs);
    }
}
